/*
 * Copyright (c) 2019 Hitevision
 */

package tw.com.hitevision.whiteboard.android.receivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import androidx.annotation.NonNull;
import tw.com.hitevision.whiteboard.android.R;

public class HhtActionBroadcastReceiver extends BroadcastReceiver {
    private static final String TAG = HhtActionBroadcastReceiver.class.getSimpleName();

    private final Listener listener;

    public HhtActionBroadcastReceiver(@NonNull Listener listener) {
        this.listener = listener;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();
        log("onReceive: intent=" + intent);
        log("- action=" + action);
        if (action == null) {
            return;
        }

        if (action.equals(context.getString(R.string.broadcast_action_two_finger))
                || action.equals(context.getString(R.string.broadcast_action_two_finger_311d))) {
            listener.onTwoFingerGesture();
        }else if(action.equals(context.getString(R.string.broadcast_action_transparent))){
            listener.notifySurfaceClear();
        }else if(action.equals(context.getString(R.string.broadcast_action_exit_open_split_mode))){
            listener.setExitSplitMenuState(true);
        }else if(action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)){
            listener.dealWithActionCloseSystemDialogs();
        }else if (action.equals("com.hht.action.exit.screenshot")){
            listener.notifyScreenShotExit();
        }
    }

    private static void log(String msg) {
        Log.d(TAG, msg);
    }

    public interface Listener {
        void onTwoFingerGesture();
        void notifySurfaceClear();
        void setExitSplitMenuState(boolean flag);
        void dealWithActionCloseSystemDialogs();
        void notifyScreenShotExit();
    }
}
